﻿namespace RLab.Programming

open System
open Microsoft.FSharp.Text.Lexing
open Ast

//Special tokens
//1 - keyword
//2 - bool exrpoession/operator
//3 - built-in function
//4 - string
//5 - comments

module CodeAnalizer =
    let tokenPositions (text : string) = 
        let lexeme lexbuf = LexBuffer<char>.LexemeString lexbuf
        let absOffset (lexbuf : LexBuffer<char>) = lexbuf.StartPos.AbsoluteOffset,(lexeme lexbuf).Length        
        let lexbuf = LexBuffer<_>.FromString  text
        let rec getPos lexb pos = 
            let cwp po = 
                let lex = lexeme lexb
                getPos lexb ((absOffset lexb,po)::pos)
            match Lexer.tokenize lexb with
            | Parser.BOOL(_) -> cwp 2
            | Parser.NOT -> cwp 2
            | Parser.AND -> cwp 2
            | Parser.OR  -> cwp 2
            | Parser.XOR -> cwp 2

            | Parser.DRIVE -> cwp 3
            | Parser.BASE -> cwp 3
            | Parser.OPEN -> cwp 3
            | Parser.CLOSE -> cwp 3
            | Parser.TYPE -> cwp 3

            | Parser.PROGSTART -> cwp 1
            | Parser.PROGEND -> cwp 1
            | Parser.IF -> cwp 1
            | Parser.ELSE -> cwp 1
            | Parser.THEN -> cwp 1
            | Parser.WHILE -> cwp 1
            | Parser.DO -> cwp 1
            | Parser.END -> cwp 1

            | Parser.STRING(_) -> cwp 4
            | Parser.SEMI(_) -> cwp 5
            | Parser.EOF -> pos 
            | _ -> cwp 0            


        getPos lexbuf []
// #r @"E:\workspace\src\rlab\Main\rlab.programming\bin\Debug\language.dll";open RLab.Programming;;
//CodeAnalizer.tokenPositions "zxc";;